package pl.edu.mimuw.mas.agent;

import pl.edu.mimuw.mas.agent.behaviour.DFRegisterBehaviour;
import pl.edu.mimuw.mas.agent.behaviour.hunting.dog.ScareFactorServerBehaviour;
import pl.edu.mimuw.mas.agent.behaviour.hunting.dog.ScareServerBehaviour;
import pl.edu.mimuw.mas.agent.behaviour.hunting.grouping.GroupingBehaviour;
import pl.edu.mimuw.mas.chart.Chart;
import pl.edu.mimuw.mas.util.AgentColor;
import pl.edu.mimuw.mas.util.PositionHelper;

public class DogAgent extends HuntingAgent {

	private static final long serialVersionUID = -4880312043463449351L;
	
	public final static String DOG_SERVICE_TYPE = "dog-service";
	
	public final static String SCARE_FACTOR_CONV = "scare-factor-conv";
	public final static String SCARE_CONV = "scare-conv";
	
	protected void setup() {
		if (!setServiceAgents()) {
			doDelete();
			return;
		}
		
		setLanguages();
		
		try {
			Object[] obj = getArguments();
			chart = (Chart) obj[0];
		} catch (Exception e) {
			logger.error("{}: Błąd podczas setup()", getName(), e);
			doDelete();
			return;
		}
		
		position = PositionHelper.getRandomPosition(this);
		
		r = AgentColor.DOG_COLOR[0];
		g = AgentColor.DOG_COLOR[1];
		b = AgentColor.DOG_COLOR[2];
		
		addBehaviour(new DFRegisterBehaviour(this, DOG_SERVICE_TYPE));
		addBehaviour(new ScareFactorServerBehaviour(this));
		addBehaviour(new ScareServerBehaviour(this));
		addHuntingBehaviour();
	}
	
	public String getServiceType() {
		return DogAgent.DOG_SERVICE_TYPE;
	}

	@Override
	public void activate() {
		setColor(AgentColor.ACTIVE_COLOR[0],
				AgentColor.ACTIVE_COLOR[1],
				AgentColor.ACTIVE_COLOR[2]);
	}

	@Override
	public void scare() {
		// muszę się zgrupować, poza tym nic nie trzeba
		// robić, bo serwer straszenia działa od początku
		addBehaviour(new GroupingBehaviour(this));
	}

}
